/*
 * Created on Feb 13, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.ba360.struts.form;

import java.text.SimpleDateFormat;
import java.util.TimeZone;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/**
 * @author ROnat
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class DealsInfoBean extends ActionForm {

	
	private int catId;
	private int dealsId;
	private int businessId;
	private String discountPrice;
	private String retailPrice;
	private String dealDesc;
	private String itemDesc;
	private String datePosted;
	private String expiry;
	private String businessType;
	private String businessName;
	private String businessAddress;
	private String areaId;
	private String zip;
	private String email;
	private String website;
	private String businessPhone;
	private String businessDesc;
	public String mainCatName;
	public String subCatName;
	public String location;
	public String place;
	public String title;
	public String category_id;
	public String subCat_id;
	public String loc_id;
	public String place_id;
	public String userId;
	public String img;
	
	/**
	 * Method validate
	 * 
	 * @param ActionMapping
	 *            mapping
	 * @param HttpServletRequest
	 *            request
	 * @return ActionErrors
	 */
	public boolean isNewDeal =false;
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors ae = new ActionErrors();
		String action = request.getParameter("action");
		if(action!=null)
		{
			if (action.equals("Confirm"))
			{
				isNewDeal = true;
		if (discountPrice.equals("") || discountPrice==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}
		if (businessAddress.equals("") || businessAddress==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}
		/*if (retailPrice.equals("") || retailPrice==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}*/
		if (zip.equals("") || zip==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}
		if (email.equals("") || email==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}
		if (email!=null){
			if (email.indexOf("@") == -1 || email.indexOf(".") == -1
					|| email.length() < 8)
				ae
						.add("Email", new ActionError(
								"error.invalidemail.value"));
			}
		if (businessPhone.equals("") || businessPhone==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}
		if (businessDesc.equals("") || businessDesc==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}
		if (title.equals("") || title==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}
		if (title.equals("") || title==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}
		if (dealDesc.equals("") || dealDesc==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
			
		}
		
		if (dealDesc!=null){
		if (dealDesc.length()>1000)	
		
		{
			ae.add("DealDesc", new ActionError("DealDescLimit"));
			return ae;
			
		}
		}
		/*if (datePosted.equals("") || datePosted==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}*/
		
		if (expiry.equals("") || expiry==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}
		if (businessName.equals("") || businessName==null)
		{
			ae.add("AFR", new ActionError("AllFieldsReq"));
			return ae;
		}
		
			}else{
				isNewDeal = false;
			}
		}else
		{
			isNewDeal =  false;
		}

	
		
	return ae;
	}
	public String getAreaId() {
		return areaId;
	}
	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}
	public String getBusinessAddress() {
		return businessAddress;
	}
	public void setBusinessAddress(String businessAddress) {
		this.businessAddress = businessAddress;
	}
	public String getBusinessDesc() {
		return businessDesc;
	}
	public void setBusinessDesc(String businessDesc) {
		this.businessDesc = businessDesc;
	}
	public int getBusinessId() {
		return businessId;
	}
	public void setBusinessId(int businessId) {
		this.businessId = businessId;
	}
	public String getBusinessName() {
		return businessName;
	}
	public void setBusinessName(String businessName) {
		this.businessName = businessName;
	}
	public String getBusinessPhone() {
		return businessPhone;
	}
	public void setBusinessPhone(String businessPhone) {
		this.businessPhone = businessPhone;
	}
	public String getBusinessType() {
		return businessType;
	}
	public void setBusinessType(String businessType) {
		this.businessType = businessType;
	}
	public int getCatId() {
		return catId;
	}
	public void setCatId(int catId) {
		this.catId = catId;
	}
	public String getDatePosted() {
		SimpleDateFormat sdf = new SimpleDateFormat("MMM,dd");
		TimeZone tz = TimeZone.getTimeZone("GMT-07:00");
		sdf.setTimeZone(tz);
		//return sdf.format(datePosted);
		return datePosted;
	}
	public void setDatePosted(String datePosted) {
		this.datePosted = datePosted;
	}
	public String getDealDesc() {
		if (isNewDeal)
			return dealDesc;
		String desc = dealDesc.replaceAll("\n","<br>");
		return desc;
	}
	public void setDealDesc(String dealDesc) {
		this.dealDesc = dealDesc;
	}
	public int getDealsId() {
		return dealsId;
	}
	public void setDealsId(int dealsId) {
		this.dealsId = dealsId;
	}
	public String getDiscountPrice() {
		return discountPrice;
	}
	public void setDiscountPrice(String discountPrice) {
		this.discountPrice = discountPrice;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getExpiry() {
		return expiry;
	}
	public void setExpiry(String expiry) {
		this.expiry = expiry;
	}
	public String getItemDesc() {
		return itemDesc;
	}
	public void setItemDesc(String itemDesc) {
		this.itemDesc = itemDesc;
	}
	public String getRetailPrice() {
		return retailPrice;
	}
	public void setRetailPrice(String retailPrice) {
		this.retailPrice = retailPrice;
	}
	public String getWebsite() {
		return website;
	}
	public void setWebsite(String website) {
		this.website = website;
	}
	public String getZip() {
		return zip;
	}
	public void setZip(String zip) {
		this.zip = zip;
	}
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	public String getMainCatName() {
		return mainCatName;
	}
	public void setMainCatName(String mainCatName) {
		this.mainCatName = mainCatName;
	}
	public String getPlace() {
		return place;
	}
	public void setPlace(String place) {
		this.place = place;
	}
	public String getSubCatName() {
		return subCatName;
	}
	public void setSubCatName(String subCatName) {
		this.subCatName = subCatName;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getCategory_id() {
		return category_id;
	}
	public void setCategory_id(String category_id) {
		this.category_id = category_id;
	}
	public String getLoc_id() {
		return loc_id;
	}
	public void setLoc_id(String loc_id) {
		this.loc_id = loc_id;
	}
	public String getPlace_id() {
		return place_id;
	}
	public void setPlace_id(String place_id) {
		this.place_id = place_id;
	}
	public String getSubCat_id() {
		return subCat_id;
	}
	public void setSubCat_id(String subCat_id) {
		this.subCat_id = subCat_id;
	}
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getImg() {
		return img;
	}
	public void setImg(String img) {
		this.img = img;
	}
}
